﻿@using Kite.Gateway.Application.Contracts
@using Kite.Gateway.Application.Contracts.Dtos.Node
@inject ToastService ToastService
@inject INodeAppService NodeAppService

<div class="row">
    <ValidateForm Model="@Model" OnValidSubmit="@OnSaveAsync" OnInvalidSubmit="@OnInvalidSubmitAsync">
           <div class="col-12">
                   <BootstrapInput @bind-Value="Model.NodeName" DisplayText="节点名称" IsTrim="true" />
             </div>
             <div class="col-12"  style="margin-top:5px;" >
                   <BootstrapInput @bind-Value="Model.Server" DisplayText="服务端地址(结尾勿带 / )" IsTrim="true" />
             </div>
              <div class="col-12"  style="margin-top:5px;" >
                   <BootstrapInput @bind-Value="Model.AccessToken" DisplayText="访问Token" IsTrim="true" />
             </div>

            <div class="col-12"  style="margin-top:5px;" >
                 <Textarea  @bind-Value="Model.Description" DisplayText="描述" IsTrim="true"/>
            </div>
            <div class="row" style="margin-top:10px;">
                <div class="col-12">
                    <Button ButtonType="ButtonType.Submit"  IsAsync="true" Color="Color.Primary">保 存</Button>
                </div>
            </div>
           </ValidateForm>
</div>


@code {

    [Parameter]
    public EventCallback OnClickCallback { get; set; }
    //表单数据
    [Parameter]
    public UpdateNodeDto Model { get; set; }
    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();
    }
    private Task OnInvalidSubmitAsync(EditContext context)
    {
        return Task.CompletedTask;
    }
    private async Task OnSaveAsync(EditContext context)
    {
        var result= await NodeAppService.UpdateAsync(Model);
        if (result.Code != 0)
        {
            await ToastService.Warning(result.Message);
        }
        else
        {
            await OnClickCallback.InvokeAsync();
            await ToastService.Success("保存成功");
        }
    }
}
